home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / src / shell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  7.9 KB  |  239 lines

  1. /* shell.h -- The data structures used by the shell */
  2.  
  3. #include "config.h"
  4. #include "general.h"
  5. #include "variables.h"
  6. #include "quit.h"
  7.  
  8. #if defined (USG) && !defined (MAXPATHLEN)
  9. #define MAXPATHLEN 1024
  10. #endif
  11.  
  12. extern int EOF_Reached;
  13.  
  14. #define NO_PIPE -1
  15. #define REDIRECT_BOTH -2
  16. #define IS_DESCRIPTOR -1
  17.  
  18. #define NO_VARIABLE -1
  19.  
  20. /* A bunch of stuff for flow of control using setjmp () and longjmp (). */
  21.  
  22. #include <setjmp.h>
  23. /**
  24.  ** (sjk)++ catch is defined in setjmp.h on the Atari ST
  25.  **/
  26. #if !defined(atarist)
  27. extern jmp_buf top_level, catch;
  28. #else
  29. extern jmp_buf top_level;
  30. #endif
  31.  
  32. #define NOT_JUMPED 0        /* Not returning from a longjmp. */
  33. #define FORCE_EOF 1        /* We want to stop parsing. */
  34. #define DISCARD 2        /* Discard current command. */
  35. #define EXITPROG 3        /* Unconditionally exit the program now. */
  36.  
  37. /* Values that can be returned by execute_command (). */
  38. #define EXECUTION_FAILURE 1
  39. #define EXECUTION_SUCCESS 0
  40.  
  41. /* Special exit status used when the shell is asked to execute a
  42.    binary file as a shell script. */
  43. #define EX_BINARY_FILE 127
  44.  
  45. /* The list of characters that are quoted in double-quotes with a
  46.    backslash.  Other characters following a backslash cause nothing
  47.    special to happen. */
  48. #define slashify_in_quotes "\\`$\""
  49. #define slashify_in_here_document "\\`$"
  50.  
  51. /* Constants which specify how to handle backslashes and quoting in
  52.    expand_word_internal ().  Q_DOUBLE_QUOTES means to use the function
  53.    slashify_in_quotes () to decide whether the backslash should be
  54.    retained.  Q_HERE_DOCUMENT means slashify_in_here_document () to
  55.    decide whether to retain the backslash.  Q_KEEP_BACKSLASH means
  56.    to unconditionally retain the backslash. */
  57. #define Q_DOUBLE_QUOTES  1
  58. #define Q_HERE_DOCUMENT  2
  59. #define Q_KEEP_BACKSLASH 3
  60.  
  61. /* All structs which contain a `next' field should have that field
  62.    as the first field in the struct.  This means that functions
  63.    can be written to handle the general case for linked lists. */
  64. typedef struct g_list {
  65.   struct g_list *next;
  66. } GENERIC_LIST;
  67.  
  68. /* Instructions describing what kind of thing to do for a redirection. */
  69. enum r_instruction { r_output_direction, r_input_direction, r_inputa_direction,
  70.              r_appending_to, r_reading_until, r_duplicating,
  71.              r_deblank_reading_until, r_close_this, r_err_and_out,
  72.              r_input_output, r_output_force };
  73.  
  74. /* Command Types: */
  75. enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple,
  76.             cm_connection, cm_function_def, cm_until, cm_group };
  77.  
  78. /* A structure which represents a word. */
  79. typedef struct word_desc {
  80.   char *word;            /* Zero terminated string. */
  81.   int dollar_present;        /* Non-zero means dollar sign present. */
  82.   int quoted;            /* Non-zero means single, double, or back quote
  83.                    or backslash is present. */
  84.   int assignment;        /* Non-zero means that this word contains an assignment. */
  85. } WORD_DESC;
  86.  
  87. /* A linked list of words. */
  88. typedef struct word_list {
  89.   struct word_list *next;
  90.   WORD_DESC *word;
  91. } WORD_LIST;
  92.  
  93.  
  94. /* **************************************************************** */
  95. /*                                    */
  96. /*            Shell Command Structs                */
  97. /*                                    */
  98. /* **************************************************************** */
  99.  
  100. /* What a redirection descriptor looks like.  If FLAGS is IS_DESCRIPTOR,
  101.    then we use REDIRECTEE.DEST, else we use the file specified. */
  102. typedef struct redirect {
  103.   struct redirect *next;    /* Next element, or NULL. */
  104.   int redirector;        /* Descriptor to be redirected. */
  105.   int flags;            /* Flag value for `open'. */
  106.   enum r_instruction  instruction; /* What to do with the information. */
  107.   union {
  108.     int dest;            /* Place to redirect REDIRECTOR to, or ... */
  109.     WORD_DESC *filename;    /* filename to redirect to. */
  110.   } redirectee;
  111.   char *here_doc_eof;        /* The word that appeared in <<foo. */
  112. } REDIRECT;
  113.  
  114. /* An element used in parsing.  A single word or a single redirection.
  115.    This is an ephemeral construct. */
  116. typedef struct element {
  117.   WORD_DESC *word;
  118.   REDIRECT *redirect;
  119. } ELEMENT;
  120.  
  121. /* Possible values for command->subshell. */
  122. #define WANT_SUBSHELL    1    /* user wants a subshell: ( command ) */
  123. #define FORCE_SUBSHELL    2    /* shell needs to force a subshell */
  124.  
  125. /* What a command looks like. */
  126. typedef struct command {
  127.   enum command_type type;    /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
  128.   int subshell;            /* Non-zero means execute in a subshell. */
  129.   int invert_pipeline;        /* Non-zero means invert return value. */
  130.   REDIRECT *redirects;        /* Special redirects for FOR CASE, etc. */
  131.   union {
  132.     struct for_com *For;
  133.     struct case_com *Case;
  134.     struct while_com *While;
  135.     struct if_com *If;
  136.     struct connection *Connection;
  137.     struct simple_com *Simple;
  138.     struct function_def *Function_def;
  139.     struct group_com *Group;
  140.   } value;
  141. } COMMAND;
  142.  
  143. /* Structure used to represent the CONNECTION type. */
  144. typedef struct connection {
  145.   COMMAND *first;        /* Pointer to the first command. */
  146.   COMMAND *second;        /* Pointer to the second command. */
  147.   int connector;        /* What separates this command from others. */
  148. } CONNECTION;
  149.  
  150. /* Structures used to represent the CASE command. */
  151.  
  152. /* Pattern/action structure for CASE_COM. */
  153. typedef struct pattern_list {
  154.   struct pattern_list *next;    /* Clause to try in case this one failed. */
  155.   WORD_LIST *patterns;        /* Linked list of patterns to test, one after each other. */
  156.   COMMAND *action;        /* Thing to execute if one of the patterns match. */
  157. } PATTERN_LIST;
  158.  
  159. /* The CASE command. */
  160. typedef struct case_com {
  161.   WORD_DESC *word;        /* the thing to test. */
  162.   PATTERN_LIST *clauses;    /* the clauses to test against, or NULL. */
  163. } CASE_COM;
  164.  
  165. /* FOR command. */
  166. typedef struct for_com {
  167.   WORD_DESC *name;    /* The variable name to get mapped over. */
  168.   WORD_LIST *map_list;    /* The things to map over.  This is never NULL. */
  169.   COMMAND *action;    /* The action to execute.
  170.                During execution, NAME is bound to successive
  171.                members of MAP_LIST. */
  172. } FOR_COM;
  173.  
  174. /* IF command. */
  175. typedef struct if_com {
  176.   COMMAND *test;        /* Thing to test. */
  177.   COMMAND *true_case;        /* What to do if the test returned non-zero. */
  178.   COMMAND *false_case;        /* What to do if the test returned zero. */
  179. } IF_COM;
  180.  
  181. /* WHILE command. */
  182. typedef struct while_com {
  183.   COMMAND *test;        /* Thing to test. */
  184.   COMMAND *action;        /* Thing to do while test is non-zero. */
  185. } WHILE_COM;
  186.  
  187. /* The "simple" command.  Just a collection of words and redirects. */
  188. typedef struct simple_com {
  189.   WORD_LIST *words;        /* The program name, the arguments,
  190.                    variable assignments, etc. */
  191.   REDIRECT *redirects;        /* Redirections to perform. */
  192. } SIMPLE_COM;
  193.  
  194. /* The "function_def" command.  This isn't really a command, but it is
  195.    represented as such for now.  If the function def appears within 
  196.    `(' `)' the parser tries to set the SUBSHELL bit of the command.  That
  197.    means that FUNCTION_DEF has to be run through the executor.  Maybe this
  198.    command should be defined in a subshell.  Who knows or cares. */
  199. typedef struct function_def {
  200.   WORD_DESC *name;
  201.   COMMAND *command;
  202. } FUNCTION_DEF;
  203.  
  204. /* A command that is `grouped' allows pipes to take effect over
  205.    the entire command structure. */
  206. typedef struct group_com {
  207.   COMMAND *command;
  208. } GROUP_COM;
  209.   
  210. /* Forward declarations of functions called by the grammer. */
  211. extern REDIRECT *make_redirection ();
  212. extern WORD_LIST *make_word_list ();
  213. extern WORD_DESC *make_word ();
  214.  
  215. extern COMMAND
  216.   *make_for_command (), *make_case_command (), *make_if_command (),
  217.   *make_while_command (), *command_connect (), *make_simple_command (),
  218.   *make_function_def (), *clean_simple_command (), *make_until_command (),
  219.   *make_group_command ();
  220.  
  221.  
  222. extern PATTERN_LIST *make_pattern_list ();
  223. extern COMMAND *global_command, *copy_command ();
  224.  
  225. extern char **shell_environment;
  226. extern WORD_LIST *rest_of_args;
  227.  
  228. /* Generalized global variables. */
  229. extern int executing, login_shell;
  230.  
  231. /* Structure to pass around that holds a bitmap of file descriptors
  232.    to close, and the size of that structure.  Used in execute_cmd.c. */
  233. struct fd_bitmap {
  234.   long size;
  235.   char *bitmap;
  236. };
  237.  
  238. #define FD_BITMAP_SIZE 32
  239.